{extend name="layout:base" /}
{block name="page_content"}
  <form class="form-horizontal adminform" id="model-form" method="post" action="">
    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
        标题：<span class="red">*</span>
      </label>
      <div class="col-sm-10">
        <input type="text" name="title" placeholder="请输入Banner标题" class="col-xs-10 col-sm-5" value="{$banner.title|default=''}" required/>

      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
        图片：<span class="red">*</span>
        <br/>1920x400(宽x高)
      </label>
      <div class="col-sm-10">
        {:add_upload_image("pc_cover_id", 300, 100, $banner['pc_cover_id'])}
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1">
        链接地址：
      </label>
      <div class="col-sm-10">
        <input type="text" name="link_url" placeholder="以http://或https://开始，例：https://www.simpleedu.com.cn/" class="col-xs-10 col-sm-5" value="{$banner.link_url|default=''}"/>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 打开方式：  </label>
      <div class="col-sm-10">
        <select name="open_target"  class="col-sm-5">
          <?php $targets = list_field_open_target(); ?>
          {volist name="targets" id="name"}
            <?php if(isset($banner['open_target']) && $banner['open_target']==$key): ?>
              <option value="{$key}" selected="selected">{$name}</option>
            <?php else: ?>
              <option value="{$key}">{$name}</option>
            <?php endif; ?>
          {/volist}
        </select>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 显示状态：  </label>
      <div class="col-sm-10" style="padding-top:5px;">
        <input name="status" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" <?php if(isset($banner["status"]) && intval($banner["status"])){echo('checked="checked"');} ?> />
        <span class="lbl"></span>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="form-group">
      <label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序编号：  </label>
      <div class="col-sm-10">
        <input type="text" name="sort" maxlength="4" placeholder="编号越小越靠前" value="{$banner.sort|default='0'}" class="col-xs-10 col-sm-5"/>
      </div>
    </div>
    <div class="space-4"></div>

    <div class="clearfix form-actions">
      <div class="col-md-offset-3 col-md-9">
        <?php if(isset($banner['id'])): ?>
          <input type="hidden" name="id" value="{$banner.id}">
        <?php endif; ?>
        <button class="btn btn-info" type="submit">
          <i class="ace-icon fa fa-check bigger-110"></i>
          保存
        </button>

        &nbsp; &nbsp; &nbsp;
        <a class="btn" href="{:url('index')}">
          <i class="ace-icon fa fa-undo bigger-110"></i>
          返回
        </a>
      </div>
    </div>
  </form>
{/block}
{block name="page_js"}
  <script src="{$site_root}/static/plugins/jquery-validate/jquery.validate.min.js"></script>
  <script type="text/javascript">
    $(document).ready(function(){
      $("form#model-form").validate({
        'ignore': '',
        rules:{
          "title":{
            required: true,
            maxlength: 60
          }, "pc_cover_id":{
            required: true
          }, "link_url":{
            url: true,
            maxlength: 250
          }, "sort":{
            min: 0,
            max: 9999
          }
        },
        messages:{
          "title":{
            required: '标题不能为空',
            maxlength: '标题长度不能超过60个字符'
          }, "pc_cover_id":{
            required: '图片不能为空'
          }, "link_url":{
            url: '链接地址格式不正确',
            maxlength: '链接地址太长'
          }, "sort":{
            min: "排序编号不能小于0",
            max: "排序编号不能大于9999"
          }
        },
        errorClass: "help-inline input-error",
        errorElement: "span",
        highlight:function(element, errorClass, validClass) {
          $(element).parents('.form-group').addClass('has-error');
        },
        unhighlight: function(element, errorClass, validClass) {
          $(element).parents('.form-group').removeClass('has-error');
          // $(element).parents('.form-group').addClass('success');
        },
        submitHandler: function(form){
          var $form = $(form);
          $.ajax({
            url: $form.attr("action"),
            type: $form.attr("method"),
            dataType: "JSON",
            data: $form.serialize(),
            success: function(data){
              if(data.code){
                location.href = data["url"];
              }else{
                alert(data["msg"]);
              }
            }, error: function () {
              alert("数据执行错误！");
            }
          });
        }
      });
    });
  </script>
{/block}